package tuanvn.iti.vn;

import java.util.List;

import mrtran.iti.vn.Main;
import mrtran.iti.vn.Main.GameView;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

public class SpriteMonster4 extends Activity {
	private GameView gameView4;
	private Bitmap bmpmonster4;
	private int widthMonster;
	private int heightMonster;
	private static final int BMP_COLUMNS_MONSTER = 7;
	private static final int BMP_ROWS_MONSTER = 2;
	public static int distance4;
	public static int monsterWidth4, widthLuffyMonster4;
	public static int xMonsterCenter4, yMonsterCenter4;
	private List<SpriteMonster4> spriteMonster4;

	int currentFrame4 = 0;
	public static int xSpeedMonster4 = 9;
	private static int ySpeedMonster4 = 0;
	int xMonster4 = Main.SCREENWIDTH / 60 - widthMonster - widthMonster,
			yMonster4 = Main.SCREENHEIGHT / 2 - heightMonster;
	int[] DIRECTION_TO_ANIMATION_MONSTER4 = {1,0 };

	public SpriteMonster4(GameView gameView4, Bitmap bmpmonster4,
			List<SpriteMonster4> spriteMonster4) {
		this.gameView4 = gameView4;
		this.bmpmonster4 = bmpmonster4;
		this.distance4 = distance4;
		this.spriteMonster4 = spriteMonster4;
		this.widthMonster = bmpmonster4.getWidth() / BMP_COLUMNS_MONSTER;
		this.heightMonster = bmpmonster4.getHeight() / BMP_ROWS_MONSTER;
	}

	private void update() {
		xMonster4 += xSpeedMonster4;
		xMonsterCenter4 = xMonster4 + widthMonster / 2;
		yMonsterCenter4 = yMonster4 + heightMonster / 2;
		monsterWidth4 = widthMonster / 2;
		if (xMonster4 > Main.SCREENWIDTH) {
			xMonster4 = -xSpeedMonster4;
			ySpeedMonster4 = 0;
		}
		currentFrame4 = ++currentFrame4 % BMP_COLUMNS_MONSTER;
	}

	public void onDraw(Canvas canvas) {
		update();
		int srcX4 = currentFrame4 * widthMonster;
		int srcY4 = getAnimationRowMonster4() * heightMonster;
		Rect src4 = new Rect(srcX4, srcY4, srcX4 + widthMonster, srcY4
				+ heightMonster);
		Rect dst4 = new Rect(xMonster4, yMonster4, xMonster4 + widthMonster,
				yMonster4 + heightMonster);
		canvas.drawBitmap(bmpmonster4, src4, dst4, null);

	}

	private int getAnimationRowMonster4() {
		double dirDouble = (Math.atan2(xSpeedMonster4, ySpeedMonster4)
				/ (Math.PI / 2) + 2);
		int direction = (int) Math.round(dirDouble) % BMP_ROWS_MONSTER;
		return DIRECTION_TO_ANIMATION_MONSTER4[direction];
	}

}
